$(function(){

var imgUrl = ["images/load.gif","images/bg1.jpg","images/bg2.jpg","images/cameraButton.png","images/logo.png"
,"images/p1.png","images/p1_w.png","images/p2.png","images/p3.png","images/p5.png","images/p6.png"
,"images/p7.png","images/p8.png","images/p9.png","images/p10.png","images/po1.jpg","images/po2.jpg","images/po3.jpg"
,"images/po4.jpg","images/po5.jpg","images/t1.png","images/t2.png","images/t3.png","images/t4.png","images/t5.png"]; 

function loadimg(imgUrl,setLoadingInfo){

  
                var len = imgUrl.length;
                var num = 0;
                var checkLoad = function(){
                    num++;
                    setLoadingInfo(parseInt(num/len*100));
                    if( num == len ){
                       
                      
                     
                      var t=setTimeout(function(){

                       $('.section0').addClass("dd"); 

                       var t2=setTimeout(function(){

                          $('.section1').hide();
                          $('.section2').show();
                          //p0swiper.startAutoplay();
                          p0swiper = new Swiper('.updata-swiper',{
                          resistanceRatio: 0,
                          initialSlide: 0,
                          autoplay : 2000,
                          autoplayStopOnLast : true,
                          direction: 'horizontal'
                      });

                       },2000);

                  },10000); 
                    
                       
                       
                    }
                };

                var checkImg = function(url){
                    var val= url;
                    var img=new Image();
                    if(img.readyState){
                      
                        img.onreadystatechange = function(){
                            if(img.readyState=="complete"||img.readyState=="loaded"){
                                checkLoad();
                            }
                        };
                    }else{

                        img.onload=function(){
                            if(img.complete==true){
                                checkLoad();
                            }
                        };
                    }
                    img.src=val;
                    
                };

                for( var i = 0; i < len; i++ ){

                    checkImg(imgUrl[i]);
                }

}

function  setLoadingInfo(num) {
                
         
       
      $('#loading_number').html(num + "%");
      
  
    }

loadimg(imgUrl,setLoadingInfo, function() {


    
});







function canvasWait( x ){
        CanvasRenderingContext2D.prototype.sector = function (x, y, radius, sDeg, eDeg) {
        // 初始保存
        this.save();
        // 位移到目标点
        this.translate(x, y);
        this.beginPath();
        // 画出圆弧
        this.arc(0,0,radius,sDeg, eDeg);
        // 再次保存以备旋转
        this.save();
        // 旋转至起始角度
        this.rotate(eDeg);
        // 移动到终点，准备连接终点与圆心
        this.moveTo(radius,0);
        // 连接到圆心
        this.lineTo(0,0);
        // 还原
        this.restore();
        // 旋转至起点角度
        this.rotate(sDeg);
        // 从圆心连接到起点
        this.lineTo(radius,0);
        this.closePath();
        // 还原到最初保存的状态
        this.restore();
        return this;
    };
            var LoadCanvas = $('#loadingcanvas')[0];
            LoadCanvas.width = 120;
            LoadCanvas.height = 120;
            var LoadCanvasCtx = LoadCanvas.getContext("2d");
            
        
        var deg = Math.PI/180;
            LoadCanvasCtx.clearRect(0,0,120,120)
            LoadCanvasCtx.beginPath();
            LoadCanvasCtx.fillStyle="#000";
            LoadCanvasCtx.arc(60,60,60,0,Math.PI*2,true);
            LoadCanvasCtx.fill();
            LoadCanvasCtx.closePath();
            
            LoadCanvasCtx.beginPath();
            LoadCanvasCtx.fillStyle="#fff";
            LoadCanvasCtx.sector(60,60,60,deg*-90,deg*( x * 3.6 - 90)).fill();
            LoadCanvasCtx.closePath();  
            
            
        var deg = Math.PI/180;
            LoadCanvasCtx.beginPath();
            LoadCanvasCtx.fillStyle="#000";
            LoadCanvasCtx.arc(60,60,55,0,Math.PI*2,true);
            LoadCanvasCtx.fill();
            LoadCanvasCtx.closePath();
            
            
            
    }


})    